﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using FreeSql;
using SqlSugar;

namespace Maltose.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            IFreeSql fsql = new FreeSql.FreeSqlBuilder()
                    .UseConnectionString(FreeSql.DataType.SqlServer, "server=.;uid=sa;pwd=123456;database=Test")
                    .Build();

            var sqlparm = new List<SqlParameter>();

            sqlparm.Add(new SqlParameter()
            {
                Value = "1",
                ParameterName = "@Name",
            });

            var parameterOut = new SqlParameter()
            {
                ParameterName = "@NameOut",
                Value = 10,
                DbType = System.Data.DbType.Int32,
                Direction = System.Data.ParameterDirection.Output
            };
            sqlparm.Add(parameterOut);


            var data = fsql.Ado.Query<UserName>(System.Data.CommandType.StoredProcedure, "PRO_UserName", sqlparm.ToArray());

            foreach (var item in data)
            {
                Console.WriteLine($" name={item.Name} msg={item.Msg} ");
            }

            Console.WriteLine($" 储存过程的值 {parameterOut.Value}");
        }
    }



    public class SqlDynamicParameter
    {
        DbParameter Parameter;

        List<SqlParameter> sqls = new List<SqlParameter>();

        public void Add(string name, string value)
        {
            sqls.Add(new SqlParameter()
            {
                ParameterName = name,
                Value = value
            });
        }

        public void AddDynamic(object value) 
        {

        }

        public T Get<T>(string name)
        {
            var value = sqls.Where(w => w.ParameterName == name).FirstOrDefault().Value;
            return (T)value;
        }
    }

    public class UserName
    {
        public string Name { get; set; }

        public string Msg { get; set; }
    }
}
